<?php

include_once ("sgbd.php");

/** delay in minutes */
function isOnline ($delay) {
	$sql_time = date( 'Y-m-d H:i:s', time() - $delay * 60);
      
	$query = "SELECT DISTINCT fk_user_login FROM LOG AS LOG1 WHERE LOG1.time > '$sql_time' AND LOG1.online = '1' AND NOT EXISTS (SELECT * FROM LOG AS LOG2 WHERE LOG1.fk_user_login = LOG2.fk_user_login AND LOG2.time > LOG1.time AND LOG2.online = '0')";

	$res = query ($query);
   
	while ($user = mysql_fetch_array($res))
		$users[] = $user[0];
   
	close ();
	return $users;
}

function wasOnline ($delay) {
	$sql_time = date( 'Y-m-d H:i:s', time() - $delay * 60);
      
	$query = "SELECT DISTINCT fk_user_login FROM LOG AS LOG1 WHERE LOG1.time > '$sql_time'";
	$res = query ($query);
   
	while ($user = mysql_fetch_array($res))
		$users[] = $user[0];
   
	close ();
	return $users;
}

?>
